package reverselist;

/**
 * 翻转链表
 *
 * @author chenkuan
 * @since 2021/3/18 018 16:48
 */
public class ReverseList {

    public <T> ListNode<T> reverse(ListNode<T> head) {
        ListNode<T> now = null;
        ListNode<T> next = null;
        while (head != null) {
            now = head;
            next = head.next;
            head.next = head.pre;
            head.pre = next;
            head = next;
        }
        return now;
    }
}
